const app = getApp();
const util = require('../../../utils/util.js');
const lbbService = require('../../../pages/service/service.js');
const lbbTaskService = require('../service/task-service.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageNo:1,
        pageSize:10,
        active:0,
        activeKey:0,
    },
    showModal(e) {
        let that = this
        wx.showModal({
          title: '取消申诉',
          content: '是否确认取消申诉?',
          complete: (res) => {
            if (res.cancel) {
              
            }
        
            if (res.confirm) {
              lbbTaskService.cancelFeeAppeal({id:e.currentTarget.dataset.id},function(res){
                    that.getAppealList()
              })
            }
          }
        })
    }, 
    //上拉加载更多
    eventhandle(e) {
        let that = this
        let pagenum = Number(that.data.pageNo)
        if (pagenum >= that.data.TotalPage) {
            that.setData({
                loading: false,
                loaded: true
            })
        } else {
            pagenum = pagenum + 1
            that.data.pageNo = pagenum.toString()
            that.setData({
                loading: true,
                loaded: false,
                pageNo:that.data.pageNo
            })
            that.getAppealList()
        }
    },
    //获取报销费用
    getAppealList(){
        let  that = this
        let params = {
            pageNo:that.data.pageNo,
            pageSize: that.data.pageSize,
            status: that.data.active,
            userId:that.data.userId
        }
        wx.showLoading({
            title: '加载中',
        })
        lbbTaskService.getFeeAppealList(params,function(res){
            res.data.records.forEach(item =>{
                if(item.images) {
                    item.images = item.images.split(',')
                }
                if(item.handleImages) {
                    item.handleImages = item.handleImages.split(',')
                }
            })
            if(that.data.pageNo==1) {
                let lists = [ ...res.data.records]
                if(lists.length==0) {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        appealList:lists
                    })
                    wx.hideLoading()
                } else {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        appealList:lists
                    })
                    wx.hideLoading()
                }
            } else {
                let lists = [...that.data.appealList, ...res.data.records]
                console.log(lists)
                if(lists.length==0) {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        appealList:lists
                    })
                    wx.hideLoading()
                } else {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        appealList:lists
                    })
                    wx.hideLoading()
                }
            }
        })
        
     },
     //预览图片
    preViewImgs(e) {
        let current = e.currentTarget.dataset.current
        let urls = e.currentTarget.dataset.imglist
        util.previewImgs(current, urls);
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            userId:options.userId
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        this.getAppealList()
    },
    // tab切换
    tabChange(e){
        let that = this
        that.data.pageNo =1
        this.setData({
            active:e.detail.index,
            appealList:[]
        })
        that.getAppealList()
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})